package JFrame;

import java.awt.CardLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class MyFrame extends JFrame implements ActionListener {
	/**
	 * 窗口类
	 */
	private static final long serialVersionUID = -4196906480972855864L;
	//实例化所需类(要切换的类(面板))
	CardLayout card=new CardLayout();   //卡片
	JPanel pane = new JPanel();
	
	HomePage c1 = new HomePage();
	Data c2 = new Data();
	Purchase c3 = new Purchase();
	Sales c4 = new Sales();
	userMana c5 = new userMana();
	public MyFrame() {
		// TODO 自动生成的方法存根
		try {
			Image imgae = ImageIO.read(new File("image/logo1.png"));
			this.setIconImage(imgae);
		} catch (IOException e) {
			e.printStackTrace();
		}
		this.setTitle("销售管理系统");
		try {
			// 将LookAndFeel设置成Windows样式
			UIManager.setLookAndFeel(
					"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		//设置卡片布局并添加画布到"卡片"中
        pane.setLayout(card);
        pane.add(c1, "home");
        pane.add(c2, "data");
        pane.add(c3, "purchase");
        pane.add(c4, "sales");
        pane.add(c5, "user");
      //按钮监听
	    c1.bt1.addActionListener(this);
		c1.bt2.addActionListener(this);	
		c1.bt3.addActionListener(this);	
		c1.bt4.addActionListener(this);	
		c1.bt5.addActionListener(this);
		c1.bt6.addActionListener(this);
		c3.home.addActionListener(this);
		c2.home.addActionListener(this);
		c4.home.addActionListener(this);
		c5.home.addActionListener(this);
		
		//设置窗口属性
		add(pane);
		setSize(800, 600);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==c1.bt1){//打开操作选项
			c1.bt2.setVisible(true);c1.e2.setVisible(true);
			c1.bt3.setVisible(true);c1.e3.setVisible(true);
			c1.bt4.setVisible(true);c1.e4.setVisible(true);
			c1.bt5.setVisible(true);c1.e5.setVisible(true);
			c1.bt6.setVisible(true);
		}else if(e.getSource()==c1.bt6){//关闭操作按钮
			c1.bt2.setVisible(false);c1.e2.setVisible(false);
			c1.bt3.setVisible(false);c1.e3.setVisible(false);
			c1.bt4.setVisible(false);c1.e4.setVisible(false);
			c1.bt5.setVisible(false);c1.e5.setVisible(false);
			c1.bt6.setVisible(false);
		}
		else if(e.getSource()==c1.bt2){//数据
			card.show(pane,"data");
		}
		else if(e.getSource()==c1.bt3){//进货单
			card.show(pane,"purchase");
		}
		else if(e.getSource()==c1.bt4){//销售单
			card.show(pane,"sales");
		}
		else if(e.getSource()==c1.bt5){//数据
			card.show(pane,"user");
		}
		else
			card.show(pane,"home");
	}
	public static void main(String[] args) {
		new MyFrame();
	}
}